﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using BitmapTagger;

namespace ImageTagEditor.ValidationRules
{
	/// <summary>
	/// Validation rule for checking if a string is in the proper format for a URational
	/// </summary>
	public class URationalValidationRule : ValidationRule
	{
		/// <summary>
		/// Checks if a string is in the proper format to be a URational
		/// </summary>
		/// <param name="value">The string to check</param>
		/// <param name="cultureInfo">Not Used</param>
		/// <returns>Whether or not the string is in proper format</returns>
		public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
		{
			if (value is string)
			{
				string stringValue = value as string;
				if (string.IsNullOrEmpty(stringValue))
					return new ValidationResult(true, null);

				try
				{
					new URational(stringValue);
					return new ValidationResult(true, null);
				}
				catch (FormatException)
				{
					return new ValidationResult(false, "Not a valid format for a URational");
				}
			}
			else
				throw new Exception("value must be of type string");
		}
	}
}